package com.mentaleye.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.mentaleye.bean.StudentInterviewRecordBean;
import com.mentaleye.biz.CompanyBiz;
import com.mentaleye.biz.StudentInterviewAnalyzeBiz;
import com.mentaleye.biz.StudentInterviewRecordBiz;
import com.mentaleye.biz.StudentsBiz;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;

@Controller
@RequestMapping("/interviewRecordController")
public class StudentInterviewRecordController {
	
	@Autowired private CompanyBiz companyBiz;
	
	@Autowired private StudentsBiz studentBiz;
	
	@Autowired
	private StudentInterviewRecordBiz recordBiz;
	
	@Autowired private StudentInterviewAnalyzeBiz analyzeBiz;

	@RequestMapping("/toListPage")
	public ModelAndView toListPage() {
		ModelAndView view = new ModelAndView("em/studentInterviewRecord/recordList");
		view.addObject("companyList",this.companyBiz.getBeanList());
		return view;
	}

	@RequestMapping("/toInsertPage")
	public ModelAndView toInsertPage() {
		ModelAndView view = new ModelAndView("em/studentInterviewRecord/recordAdd");
		view.addObject("studentList", this.studentBiz.getBeanList());
		view.addObject("companyList",this.companyBiz.getBeanList());
		return view;
	}
	
	@RequestMapping("/toEditPage")
	public ModelAndView toEditPage(@RequestParam long recordId) {
		ModelAndView view = new ModelAndView("em/studentInterviewRecord/recordEdit");
		view.addObject("recordBean",this.recordBiz.getRecordById(recordId));
		return view;
	}

	@RequestMapping("/toDetailPage")
	public ModelAndView toDetailPage(@RequestParam long recordId) {
		ModelAndView view = new ModelAndView("em/studentInterviewRecord/recordDetail");
		view.addObject("recordBean", this.recordBiz.getRecordById(recordId));
		view.addObject("analyzeBean", this.analyzeBiz.getBeanByInterviewId(recordId));
		return view;
	}
	
	@RequestMapping("/insertData")
	@ResponseBody
	public String insertData(StudentInterviewRecordBean recordBean) {
        CommonResult result = this.recordBiz.insertRecord(recordBean);
		return JSON.toJSONString(result);
	}

	@RequestMapping("/updateData")
	@ResponseBody
	public String updateData(StudentInterviewRecordBean recordBean) {
		CommonResult result = this.recordBiz.updateRecord(recordBean);
		return JSON.toJSONString(result);
	}

	@RequestMapping("/deleteData")
	@ResponseBody
	public String deleteData(@RequestBody List<Long> idList) {
		CommonResult result = this.recordBiz.deleteByKeyList(idList);
		return JSON.toJSONString(result);
	}

	@RequestMapping("/getList")
	@ResponseBody
	public String getList(CommonPage page) {
        this.recordBiz.getListByPage(page);;
        return page.toSHowPage();
	}
}
